package com.tms.warehouse;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class ProfileTypeController extends BaseController {

	private static final String PARAMETER_ID = "entityId";
	private static final String PARAMETER_NAME = "name";
	private static final String PARAMETER_ARTICLE_NUMBER = "articleNumber";
	private static final String PARAMETER_SERIES = "seriesId";
	private static final String PARAMETER_SHELF = "shelfId";

	@Override
	protected String doListAction(HttpServletRequest req,
			HttpServletResponse resp) {

		req.setAttribute("entities", Warehouse.getAllProfileTypes());
		return "./type.jsp";
	}

	@Override
	protected String doCreateAction(HttpServletRequest req,
			HttpServletResponse resp) {

		req.setAttribute("shelves", Warehouse.getAllShelves());
		req.setAttribute("series", Warehouse.getAllSeries());
		return "./type.jsp";
	}

	@Override
	protected String doEditAction(HttpServletRequest req,
			HttpServletResponse resp) {

		String entityId = req.getParameter(PARAMETER_ID);
		req.setAttribute("entity", Warehouse.findProfileTypeById(entityId));
		req.setAttribute("shelves", Warehouse.getAllShelves());
		req.setAttribute("series", Warehouse.getAllSeries());
		return "./type.jsp";
	}

	@Override
	protected String doDeleteAction(HttpServletRequest req,
			HttpServletResponse resp) {

		String entityId = req.getParameter(PARAMETER_ID);
		Warehouse.deleteProfileType(entityId);
		return TARGET_SELF;
	}

	@Override
	protected String doSaveAction(HttpServletRequest req,
			HttpServletResponse resp) {

		String entityId = req.getParameter(PARAMETER_ID);
		String name = req.getParameter(PARAMETER_NAME);
		String articleNumber = req.getParameter(PARAMETER_ARTICLE_NUMBER);
		String shelfId = req.getParameter(PARAMETER_SHELF);
		String seriesId = req.getParameter(PARAMETER_SERIES);
		Warehouse.persistProfileType(entityId, name, articleNumber, seriesId,
				shelfId);
		return TARGET_SELF;
	}

}
